﻿using Autofac;
using Autofac.Extras.DynamicProxy;
using commonFramwork.CacheManager;
using commonFramwork.Interceptor;
using Ef.Repository.Infrastructure;
using Ef.Repository.Interface;
using Ef.Repository.Repository;
using EF.Framework.Ef;
using Entity.Framework;
using My.BLL.CacheService;
using My.BLL.NewService;
using Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace My.BLL.boot
{
    public class AutofacBootstrapper
    {

        public static ContainerBuilder Configure()
        {
            var containerBuilder = new ContainerBuilder();


            //缓存拦截
            containerBuilder.Register(c => new CacheIntercetor());
            //日志拦截
            containerBuilder.Register(c => new CallLogger());

            containerBuilder.RegisterType<DatabaseFactory>().As<IDatabaseFactory>().InstancePerRequest();
            containerBuilder.RegisterType<UserRepository>().As<IUserRepository>().InstancePerRequest();
            containerBuilder.RegisterType<Entity.Framework.Respositories.UserRepository>().As<Entity.Framework.InterFace.IUserRepository>().InstancePerRequest();
            containerBuilder.RegisterType<DemoRepository>().As<IDemoRepository>().InstancePerRequest(); 
            containerBuilder.RegisterType<CacheProvider>().As<ICacheProvider>().SingleInstance();  //全局唯一  重要
            containerBuilder.RegisterType<EntityFrameworkRepositoryContext>().As<IRepositoryContext>().InstancePerRequest();

            containerBuilder.RegisterType<UserCacheService>().As<IUserCacheService>().EnableInterfaceInterceptors();
            containerBuilder.RegisterType<NewMyServices>().As<INewMyServices>().InstancePerRequest().EnableClassInterceptors();
            //containerBuilder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
            return containerBuilder;
        }
    }
}
